package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.edu.mvcframework.annotations.LagouAutowired;
import com.lagou.edu.mvcframework.annotations.LagouController;
import com.lagou.edu.mvcframework.annotations.LagouRequestMapping;
import com.lagou.edu.mvcframework.annotations.Security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Security({"zhangsan","lisi"})
@LagouController
@LagouRequestMapping("/security")
public class SecurityController {

    @LagouAutowired
    private IDemoService demoService;

    /**
     * URL: /demo/query?name=lisi
     * @param request
     * @param response
     * @param username
     * @return
     */
    @LagouRequestMapping("/query")
    public void query(HttpServletRequest request, HttpServletResponse response,String username) {
        username = demoService.get(username);
        PrintWriter writer = null;
        try {
            writer = response.getWriter();
            writer.println(username);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (writer!=null) {
                writer.close();
            }
        }
    }
}
